<template>
  <!-- 方案规划导航栏 -->
   <div style="width: 100%;height: 150%;text-align: center;">

    <div class="box1">
        
      <div class="mapDiv" id="container"></div>
    
      <el-form ref="form" style="text-align: left;float: left;" :inline="true" class="demo-form-inline" label-position="right" :model="form" label-width="120px">
        <el-form-item label="制氢地址：">
          
          <el-select v-model="form.valueProvince" placeholder="请选择省" @change="changeProvince" style="width:120px">
            <el-option
              v-for="item in provinceList"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>

                
          <el-select v-model="form.valueCity" placeholder="请选择市" @change="changeCity" style="width:120px">
            <el-option
              v-for="item in cityOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>

          <el-link @click="onSearch" style="color: #409EFF;">定位</el-link>

        </el-form-item>
    
        <el-form-item label="经纬度：">
          <el-input readonly="true" style="width: 100%;"  v-model="form.latLng"> 
          </el-input>
        </el-form-item>
        
        <el-form-item>
          <el-link @click="showLineData('solarEnergy')" style="color: #409EFF;">太阳能数据</el-link>
          <el-link @click="showLineData('windEnergy')" style="color: #409EFF;">⻛能数据</el-link>

        </el-form-item>

      </el-form>

    </div>

    

    
    <div id="elePriceDiv" style="display: flex;" class="box">
 
      <el-form :inline="true" :model="formInline" style="margin-left: 2vh;margin-top: 1vh;width: 20%;" class="demo-form-inline">
        <el-form-item label="电价:">

          <el-radio-group @change="elecPriceChange" v-model="form.elecPriceType"> 
            <el-radio label="fixedElecPrice">固定电价</el-radio>
            <el-radio label="variableElecPrice">峰⾕电价</el-radio>
          </el-radio-group>

        </el-form-item>
      
      </el-form>

      <el-form v-if="this.form.elecPriceType=='fixedElecPrice'" :inline="true" :model="formInline" style="margin-left: 2vh;margin-top: 1vh;    width: 74%;float: left;text-align: left;" class="demo-form-inline">
        <el-form-item label="购电价格:">
          <el-input style="width: 90%;margin-top: -0.6vh;" v-model="form.purchasPriceElectricity">
              <template slot="append">元/kWh</template>
            </el-input>
        </el-form-item>

       
      
      </el-form>

      
      <el-form v-if="this.form.elecPriceType=='variableElecPrice'" :inline="true" :model="formInline" style="margin-left: 2vh;margin-top: -2vh;width: 91%;float: left;" class="demo-form-inline">
        <el-row gutter="20"> 
          <el-form-item label="峰时电价:">
            <el-input style="width: 90%;margin-top: 0vh;" v-model="form.peakHourElecPrice">
                <template slot="append">元/kWh</template>
              </el-input>
          </el-form-item>
          <el-form-item label="峰时段:">
            <el-col :span="6">
              <el-input style="width: 100%;margin-top: 0vh;" v-model="form.peakHourStart"></el-input>
            </el-col>
            <el-col :span="2">
              <span style="color: #f2f2f2;">~</span>
            </el-col>
            <el-col :span="6">
              <el-input style="width: 100%;margin-top: 0vh;" v-model="form.peakHourEnd"></el-input>
            </el-col>
          </el-form-item>
        </el-row>

        <el-row gutter="20"> 
          <el-form-item label="⾕时电价:">
            <el-input style="width: 90%;margin-top: 0vh;" v-model="form.hourlyHourElecPrice">
                <template slot="append">元/kWh</template>
              </el-input>
          </el-form-item>
          <el-form-item label="⾕时段:">
            <el-col :span="6">
              <el-input style="width: 100%;margin-top: 0vh;" v-model="form.hourlyHourStart"></el-input>
            </el-col>
            <el-col :span="2">
              <span style="color: #f2f2f2;">~</span>
            </el-col>
            <el-col :span="6">
              <el-input style="width: 100%;margin-top: 0vh;" v-model="form.hourlyHourEnd"></el-input>
            </el-col>
          </el-form-item>
        </el-row>
        
        <el-row gutter="20"> 
          <el-form-item label="平时电价:">
            <el-input style="width: 90%;margin-top: 0vh;" v-model="form.regularHourElecPrice">
                <template slot="append">元/kWh</template>
              </el-input>
          </el-form-item>
          <el-form-item label="平时段:">
            <el-col :span="6">
              <el-input style="width: 100%;margin-top: 0vh;" v-model="form.regularHourStart"></el-input>
            </el-col>
            <el-col :span="2">
              <span style="color: #f2f2f2;">~</span>
            </el-col>
            <el-col :span="6">
              <el-input style="width: 100%;margin-top: 0vh;" v-model="form.regularHourEnd"></el-input>
            </el-col>
          </el-form-item>
        </el-row>

             
        <el-row gutter="20"> 
          <el-form-item label="尖时电价:">
            <el-input style="width: 90%;margin-top: 0vh;" v-model="form.sharpHourElecPrice">
                <template slot="append">元/kWh</template>
              </el-input>
          </el-form-item>
          <el-form-item label="尖时段:">
            <el-col :span="6">
              <el-input style="width: 100%;margin-top: 0vh;" v-model="form.sharpHourStart"></el-input>
            </el-col>
            <el-col :span="2">
              <span style="color: #f2f2f2;">~</span>
            </el-col>
            <el-col :span="6">
              <el-input style="width: 100%;margin-top: 0vh;" v-model="form.sharpHourEnd"></el-input>
            </el-col>
          </el-form-item>
        </el-row>
      
      </el-form>


      <div id="buttonDiv" style="margin-top: 0.9vh;width:17%;text-align: right;margin-right: 1vh;">
        <el-button type="primary" @click="uploadElecPriceData()" style="width: 80px">
          <span class="button-text">上传</span>
        </el-button>
      </div>
  </div>
 
 
  
  <div id="box2DIv" class="box2">
 
    <el-form :inline="true" :model="formInline" style="margin-left: 2vh;margin-top: 6px;width: 98%;float: left;text-align: left;" class="demo-form-inline">
      <el-row gutter="20"> 

        <el-col  :span="7"> 
          <el-form-item label-width="120px" label="售电价格:">
            <el-input style="width: 85%;margin-top: 0vh;" v-model="form.electricitySellingPrice">
                <template slot="append">元/kWh</template>
              </el-input>
          </el-form-item>
        </el-col>

        <el-col :span="6"> 
          <el-form-item  label-width="100px"  label="购氢价格:"  style="display: inline-flex;" >
            <el-input style="width: 80%;margin-top: 0vh;" v-model="form.purchasePriceHydrogen">
                <template slot="append">元/kg</template>
              </el-input>
          </el-form-item>
        </el-col>

        <el-col :span="12"> 

        </el-col>
        
         
      </el-row>

      <el-row gutter="20"> 
 
        <el-col :span="6.6"> 

          <el-form-item label-width="120px" style="display: inline-flex;" label="购氢碳排放量:">
              <el-input style="width: 74%;margin-top: 0vh;" v-model="form.carbonEmissions">
                <template slot="append">Kg CO2/kg H2</template>
              </el-input>
          </el-form-item>

        </el-col>
        
        <el-col :span="5">
          <el-form-item label-width="75px" style="display: inline-flex;" label="折现率:">
            <el-input style="width: 93%;margin-top: 0vh;" v-model="form.discountRate">
                <template slot="append">%</template>
              </el-input>
          </el-form-item>
        </el-col>

        <el-col :span="6"> 
          <el-form-item label-width="300px" style="display: inline-flex;"  label="容量综合匹配度（默认95%）:">
            
              <el-input style="width: 80%;margin-top: 0vh;" v-model="form.matchingDegree">
                <template slot="append">%</template>
              </el-input>
         
          </el-form-item>
        </el-col>

        <el-button type="primary" @click="savePageData()" style="width: 80px;margin-left: 28.9vh;">
          <span class="button-text">保存</span>
        </el-button>
         
      </el-row>

      
    </el-form>

  </div>


  <!-- 曲线弹窗 -->
  <div>
    <el-dialog title="8760数据" :visible.sync="lineShowFlag"  width="150vh" style="margin-top: 15vh;width: 150vh;margin-left: 40vh;" align="left">
      
      <div id="lineCharts" style="width: 98%;height: 30vh;margin: 0 auto;"> 
        
      </div>

      <div slot="footer">
        <el-button type="primary" @click="uploadLineData()">上传</el-button>
        <el-button type="primary" @click="closeLineWindow()">返回</el-button>
      </div>
    </el-dialog>
  </div>
  <!-- 曲线弹窗 -->
  
  
        
  <!-- 上传弹窗 -->
  <div>
    <el-dialog :title="dialogTitle" :visible.sync="dialogShowFlag"  width="80vh" align="left">
      
      <div class="uploadModal">
        
        <div class="modal-body">
          
          <el-link style="color: #2e44ff;font-size: 1vw;" @click="downloadTemp()" class="modal-description">下载模版，填写信息</el-link>
          <button class="upload-area">
            <span class="upload-area-icon">
              <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="340.531" height="419.116" viewBox="0 0 340.531 419.116">
                <g id="files-new" clip-path="url(#clip-files-new)">
                  <path id="Union_2" data-name="Union 2" d="M-2904.708-8.885A39.292,39.292,0,0,1-2944-48.177V-388.708A39.292,39.292,0,0,1-2904.708-428h209.558a13.1,13.1,0,0,1,9.3,3.8l78.584,78.584a13.1,13.1,0,0,1,3.8,9.3V-48.177a39.292,39.292,0,0,1-39.292,39.292Zm-13.1-379.823V-48.177a13.1,13.1,0,0,0,13.1,13.1h261.947a13.1,13.1,0,0,0,13.1-13.1V-323.221h-52.39a26.2,26.2,0,0,1-26.194-26.195v-52.39h-196.46A13.1,13.1,0,0,0-2917.805-388.708Zm146.5,241.621a14.269,14.269,0,0,1-7.883-12.758v-19.113h-68.841c-7.869,0-7.87-47.619,0-47.619h68.842v-18.8a14.271,14.271,0,0,1,7.882-12.758,14.239,14.239,0,0,1,14.925,1.354l57.019,42.764c.242.185.328.485.555.671a13.9,13.9,0,0,1,2.751,3.292,14.57,14.57,0,0,1,.984,1.454,14.114,14.114,0,0,1,1.411,5.987,14.006,14.006,0,0,1-1.411,5.973,14.653,14.653,0,0,1-.984,1.468,13.9,13.9,0,0,1-2.751,3.293c-.228.2-.313.485-.555.671l-57.019,42.764a14.26,14.26,0,0,1-8.558,2.847A14.326,14.326,0,0,1-2771.3-147.087Z" transform="translate(2944 428)" fill="var(--c-action-primary)"/>
                </g>
              </svg>
            </span>
            <span class="upload-area-title">请选择您要上传的文件，仅支持xls,xlsx格式文件</span>
            <span class="upload-area-description">
              <br/><strong @click="goFile()">点击上传</strong>
            </span>
          </button>
        </div>
        <form style="display: none;" enctype="multipart/form-data">
            <input type="file" id="file" name="file" ref="files" @change="importData($event)"
                accept=".xls,.xlsx" />
        </form>
        <div class="modal-footer">
          <!-- <el-button type="primary" @click="confirmUpload()">确认上传</el-button> -->
          <el-button type="primary" @click="closeWindow()">取消</el-button>
        </div>
      </div>

 
    </el-dialog>
  </div>
  <!-- 上传弹窗 -->
  

 
</div>
  
</template>
<script type="text/javascript">
    window._AMapSecurityConfig = {
        securityJsCode: 'b6a7ea952a94b534734e60f1c322c5d8',
    }
</script>

<script type="text/javascript" src="https://webapi.amap.com/maps?v=2.0&key=3c40b24a0968cfbc241dce18366a6553&plugin=AMap.Driving"></script>


<script>
import AMapLoader from "@amap/amap-jsapi-loader";

import jsonData from '../../assets/js/china_address.json'

let echarts = require('echarts/lib/echarts');


var lineOption = {
   //backgroundColor: '#0F224C', //背景色
   title: {
		text: '',
		textStyle: {
			color: '#FFF',
			fontSize: 20
		},
		top:"2%",
		left: 'center',
// 		right: '5%'
	},
   grid: {
      left : '3%',
      right : '4%',
      bottom : '5%',
      top : '20%',
      containLabel: true
   },
   tooltip: {
      trigger: "axis",
      axisPointer: {
         lineStyle: {
            color: "rgba(255,255,255,0.7)"
         }
      },
      backgroundColor: "rgba(255,255,255,0.1)",
      padding: [5, 10],
      textStyle: {
         color: "rgb(255,255,255)"
      }
   },
   legend: {
      x: "center",
      y: "bottom",
      icon: "circle",
      itemWidth: 12,
      itemHeight: 12,
      itemGap: 60,
      textStyle: {
         color: "#C0C4CC",
         fontSize: 13,
         fontWeight: 'bold',
      },
      data: [""]
   },
   xAxis: {
      name: '(小时)', 
      nameTextStyle: {
        color: '#f2f2f2',
        padding: [0, -10, -5, 0]
      },
      type: "category",
      data: [],
      boundaryGap: true,
      splitLine: {
         show: false
      },
      axisTick: {
         show: false
      },
      // type: 'dashed',
      axisLine: {
         lineStyle: {
            type: 'dashed',
            color: "#2557B4"
         }
      },
      axisLabel: {
         margin: 10,
         textStyle: {
            fontSize: 14,
            color: "#C0C4CC"
         }
      }
   },
   yAxis: [
      {
         type: "value",
         position: "center",
         name: '',
         scale : true,
         nameTextStyle: {
            padding: [0, 0, 0, 0],
            color: '#C0C4CC',
            fontSize: 13,
            fontWeight: 'bold',
            // lineHeight: 40,
         },
         splitLine: {
            show: true,
            lineStyle: {
               type: 'dashed',
               color: "#C0C4CC"
            }
         },
         axisLine: {
            show: true,
            lineStyle: {
               color: "rgba(255,255,255,0.3)"
            }
         },

         axisLabel: {
            show: true,
            margin: 2,
            textStyle: {
               fontSize: 12,
               color: "#DEEBFF"
            }
         }
      },],
     //dataZoom 组件 用于区域缩放
          
     dataZoom: [{
        type: 'slider',
        realtime: true,
        //移动端展示方式
        handleSize: '100%', //滑动条两侧的大小
          start: 0,
          end: 50,
    }],
   series: [
      {
         name: "数据",
         type: "line",
         smooth: true,
         showSymbol: false,
         symbol: 'circle',
         // showSymbol: true,
         // symbol: 'circle',
         data: [],
         itemStyle: {
            normal: {
               color: '#287CE8'
            }
         },
         lineStyle: {
            normal: {
               width: 3
            }
         },


      }
      
   ]
}



  export default {
    name: 'heResourceParameters',
    data() {
      return {
      
        form: {
          id: '',
          projectId: '',
          type: 'he',
          latLng: '', 
          valueProvince : "",
          valueCity : "",
          cityName : "",
          elecPriceType: 'fixedElecPrice',
          purchasPriceElectricity: '',
          electricitySellingPrice: '',
          peakHourElecPrice: '',
          peakHourStart: '',
          peakHourEnd: '',
          hourlyHourElecPrice: '',
          hourlyHourStart: '',
          hourlyHourEnd: '',
          regularHourElecPrice: '',
          regularHourStart: '',
          regularHourEnd: '',

          sharpHourElecPrice: '',
          sharpHourStart: '',
          sharpHourEnd: '',
          discountRate: '',
          purchasePriceHydrogen: '',
          carbonEmissions: '',
          matchingDegree : ''
        },
        projectId: '',

 
        activeDate: '',
        type: '', 
        
        provinceList: [], // 省列表
        cityList: [], // 市列表
        originList: [], // 区列表
        valueProvince: '', // 所选的省
        valueCity: '', // 所选的市
        valueOrigin: '', // 所选的区
        cityOptions: [], // 市下拉框数据
        originOptions: [],// 区下拉框数据

        lineShowFlag : false,
        dataType : "",
        dialogTitle : "上传负荷数据",
        dialogShowFlag : false,
        templateName : "elecPriceTemplate.xlsx",
        uploadUrl : "/iepsapi/ea/hpEconomicAnalysis/importLoadPowerData"

      }
    },
    created() {
      this._getJsonData();
    },
    mounted: function() {
      this.projectId = this.$route.query.projectId;
      this.form.projectId = this.projectId;
      this.queryPageData();
    },
    methods: {

      uploadElecPriceData : function(){
        this.dialogTitle = "上传峰谷电价数据";
        this.templateName = ".xlsx";
        this.uploadUrl = "/iepsapi/ea/hpEconomicAnalysis/importElecPriceData";
        this.dialogShowFlag = true;
      },

      uploadLineData : function(){
        this.dialogTitle = "上传8760数据";
        this.templateName = "loadTemplate.xlsx";
        this.uploadUrl = "/iepsapi/ea/hpEconomicAnalysis/importLoadPowerData";
        this.dialogShowFlag = true;
      },

      closeWindow : function(){
        this.dialogShowFlag = false;
      },
      closeLineWindow : function(){
        this.lineShowFlag = false;
      },
      goFile() {
          this.$refs.files.click();
      },
      downloadTemp: function () { 
        
        if(this.dataType == "windEnergy"){
          this.templateName = "heWindEnergy.xlsx";
        }else if(this.dataType == "solarEnergy"){
          this.templateName = "heSolarEnergy.xlsx";
        }
        window.open('/iepsapi/ea/hpEconomicAnalysis/downloadTemp?templateName=' + this.templateName, '_self');
      },
      
      //导入
      importData: function (file) {
          var vm = this;
          var files = file.target.files[0];
          var fileName = files.name;
          if (!files) {
              return;
          }
          if (files.type === "application/vnd.ms-excel" || files.type === "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") {
              var formData = new FormData();
              formData.append('file', file.target.files[0]);
              formData.append('fileName', fileName);
              formData.append('importType', vm.dataType);

              formData.append('type', vm.form.type);
              formData.append('tableName', "ew_resource_parameters");
              formData.append('id', vm.form.id); 
              const loading = this.$loading({
                  lock: true,
                  text: "正在导入...",
                  spinner: "hy-icon-loading",
                  background: "rgba(0, 0, 0, 0.7)",
              });
              $.ajax({
                  type: 'post',
                  url: vm.uploadUrl,
                  data: formData,
                  cache: false,
                  processData: false,
                  contentType: false,
                  timeout: 300000, // 设置超时时间为300000毫秒（即5分钟） 
                  success: function (res) {
                      //成功执行的代码
                      loading.close();
                      var state = res.state;
                      if (state == 'error') {
                
                          vm.$message({
                            message: res.message,
                            type: 'info'
                          });
                      } else {
                  
                          vm.$message({
                            message: '导入成功',
                            type: 'success'
                          });
                          vm.dialogShowFlag = false;
                      }
                      setTimeout(() => {
                        if(vm.templateName=="loadTemplate.xlsx"){
                          vm.showLineData(vm.dataType);;
                        }else{
                          vm.queryPageData();
                        }
                      }, 1000);



                  },
                  error: function (xhr, textStatus, errorThrown) {
                      loading.close();
                      // 处理超时错误
                      if (textStatus == 'timeout') {
                          // 超时后的处理逻辑
                          vm.$message({
                            message: '后台导入中',
                            type: 'info'
                          });
                      } else {
                          vm.$message({
                            message: '导入失败',
                            type: 'error'
                          });
                      }
                  }
              })
          } else {
              this.$message({
                  message: '文件格式错误！',
                  type: 'error'
              });
              return;
          }
      },


      
      showLineData : function(dataType){

        this.lineShowFlag = true;

        this.dataType = dataType;
        
        var vm = this;

        this.$http.post('/iepsapi/ea/hpEconomicAnalysis/getLineData?id='+this.form.id+"&type="+dataType+"&tableName=excel_data").then((res) => {
          var result = res.data;
          if(result){
 
            var xAxisData = result.xAxisData;
            var seriesData = result.seriesData;

            let lineCharts = this.$echarts.init(document.getElementById('lineCharts'))
      
            lineCharts.clear(); 

            lineOption.xAxis.data = xAxisData;
            lineOption.series[0].data = seriesData;

            if(vm.dataType == "solarEnergy"){
              lineOption.yAxis[0].name = "W/m2";
            }else if(vm.dataType == "windEnergy"){
              lineOption.yAxis[0].name = "m/s";
            }

            lineCharts.setOption(lineOption); 

            window.onresize = function(){
              lineOption.resize(); 
            }

          }
        }).catch((error) => {
          console.log(error);
        });

      },
      
      savePageData : function(){
 
        var vm = this;
        this.$http.post('/iepsapi/ea/hpEconomicAnalysis/savePageData', {
          "pageData": JSON.stringify(this.form),
          "tableName":"he_resource_parameters"
        }).then((res) => {
        
          if (res.data.flag) {
            vm.form.id = res.data.id;
            this.$message({
              type: 'success',
              message: res.data.message
            });

          } else {
            this.$message.error(res.data.message);
          }
        });

      },

      
      queryPageData : function(){

        var vm = this;

        this.$http.post('/iepsapi/ea/hpEconomicAnalysis/queryPageData?projectId='+this.projectId+"&tableName=he_resource_parameters").then((res) => {
          var result = res.data.data;

          if(result){
            vm.form = result;

            vm.valueProvince = vm.form.valueProvince;
            vm.valueCity = vm.form.valueCity;

            vm.changeProvince(vm.valueProvince);
            vm.changeCity(vm.valueCity);
            vm.elecPriceChange();

            setTimeout(function(){
              vm.changeCity(vm.valueCity);
            },1000);



            var latLng = vm.form.latLng;

            var split = latLng.split(",");

            window._AMapSecurityConfig = {
              securityJsCode: 'b6a7ea952a94b534734e60f1c322c5d8',
            } 

            AMapLoader.load({
                key: "3c40b24a0968cfbc241dce18366a6553", // 申请好的Web端开发者Key，首次调用 load 时必填
                
                version: "2.0", // 指定要加载的 JSAPI 的版本，缺省时默认为 1.4.15
                resizeEnable: true,
                plugins: [
                    "AMap.ToolBar", //工具条
                    "AMap.Scale", // 比例尺
                    "AMap.Geolocation", //定位
                ], // 需要使用的的插件列表，如比例尺'AMap.Scale'等
            }).then((AMap) => {
                console.log(AMap);
                this.map = new AMap.Map("container", { //设置地图容器id
                    resizeEnable: true,
                    rotateEnable: true,
                    pitchEnable: true,
                    zoom: 8,
                    pitch: 80,
                    rotation: -15,
                    viewMode: '2D',//开启3D视图,默认为关闭
                    buildingAnimation: true,//楼块出现是否带动画
                    expandZoomRange: true,
                    zooms: [3, 20],
                    center: [split[0],split[1]], //初始化地图中心点位置
                });
                  
            }).catch(e => {
                console.log(e);
            })

          }else{

            
            window._AMapSecurityConfig = {
              securityJsCode: 'b6a7ea952a94b534734e60f1c322c5d8',
            } 

            AMapLoader.load({
                key: "3c40b24a0968cfbc241dce18366a6553", // 申请好的Web端开发者Key，首次调用 load 时必填
                
                version: "2.0", // 指定要加载的 JSAPI 的版本，缺省时默认为 1.4.15
                resizeEnable: true,
                plugins: [
                    "AMap.ToolBar", //工具条
                    "AMap.Scale", // 比例尺
                    "AMap.Geolocation", //定位
                ], // 需要使用的的插件列表，如比例尺'AMap.Scale'等
            }).then((AMap) => {
                console.log(AMap);
                this.map = new AMap.Map("container", { //设置地图容器id
                    resizeEnable: true,
                    rotateEnable: true,
                    pitchEnable: true,
                    zoom: 8,
                    pitch: 80,
                    rotation: -15,
                    viewMode: '2D',//开启3D视图,默认为关闭
                    buildingAnimation: true,//楼块出现是否带动画
                    expandZoomRange: true,
                    zooms: [3, 20],
                    center: [117.120128,36.652069], //初始化地图中心点位置
                });
                  
            }).catch(e => {
                console.log(e);
            })

          }
        }).catch((error) => {
          console.log(error);
        });


      },
      
      
      onSearch:function(){

        var vm = this;

        AMapLoader.load({
            key:"3c40b24a0968cfbc241dce18366a6553", // key
            version:"2.0", // 指定要加载的 JSAPI 的版本，缺省时默认为 1.4.15
            plugins:['AMap.DistrictSearch'], // 需要使用的的插件列表
        }).then((AMap) => {
            // level (string) 关键字对应的行政区级别或商圈，可选值： country：国家 province：省/直辖市 city：市 district：区/县 biz_area：商圈
            // subdistrict (number) 显示下级行政区级数（行政区级别包括：国家、省/直辖市、市、区/县4个级别），商圈为区/县下一 级，可选值：0、1、2、3，默认值：1 0：不返回下级行政区 1：返回下一级行政区 2：返回下两级行政区 3：返回下三级行政区
            // extensions (string) 是否返回行政区边界坐标点，默认值：base，不返回行政区边界坐标点，取值：all，返回完整行政区边界坐标点
            const district = new AMap.DistrictSearch({subdistrict:0,extensions:'all',level:'province'});
            district.search(this.form.valueCity,function(status, result){
                // 查询成功时，result即为对应的行政区信息
                // console.log(result.districtList[0].boundaries,222) // 这里是整个郑州市的边界经纬度
                const bounds = result.districtList[0].boundaries
                vm.form.cityName = result.districtList[0].name;

                var lat = result.districtList[0].center.lat;
                var lng = result.districtList[0].center.lng;
               
                vm.form.latLng = lng+","+lat;

                const mask = []
                for (let i=0;i<bounds.length;i++){
                    mask.push([bounds[i]])
                }
                const map = new AMap.Map("container",{  // 设置地图容器id
                    mask: mask, // 为Map实例制定掩模的路径,各图层将值显示路径范围内图像,3D模式下有效
                    zoom:10, // 设置当前显示级别
                    expandZoomRange:true, // 开启显示范围设置
                    zooms: [7, 20], //最小显示级别为7，最大显示级别为20
                    center:[lng,lat], // 设置地图中心点位置
                    viewMode:"2D",    // 特别注意,设置为3D则其他地区不显示
                    zoomEnable:true, // 是否可以缩放地图
                    resizeEnable:true,
                    /*mapStyle(地图的显示样式) 可以不写，默认是amap://styles/d6bf8c1d69cea9f5c696185ad4ac4c86
                    目前支持两种地图样式： 第一种：自定义地图样式，如 "amap://styles/d6bf8c1d69cea9f5c696185ad4ac4c86"
                    可前往地图自定义平台定制自己的个性地图样式； 第二种：官方样式模版,如"amap://styles/grey"。 其他模版样式及自定义地图的使用说明见开发指南*/
                    // mapStyle: "amap://styles/d6bf8c1d69cea9f5c696185ad4ac4c86"
                    // mapStyle: "amap://styles/grey"
                    // mapStyle: "amap://styles/light"
                });
                // 添加描边
                for (let i=0;i<bounds.length; i++) {
                    const polyline = new AMap.Polyline({
                        path:bounds[i], // polyline 路径，支持 lineString 和 MultiLineString
                        strokeColor:'#3078AC', // 线条颜色，使用16进制颜色代码赋值。默认值为#00D3FC
                        strokeWeight:2, // 轮廓线宽度,默认为:2
                        // map:map // 这种方式相当于: polyline.setMap(map);
                    })
                    polyline.setMap(map);
                }
            })
        }).catch(e=>{
            console.log(e);
        }) 

      },



      // 选择省
      changeProvince(val) {
        this.provinceList.forEach((province, index) => {
          if (val.toString() === this.provinceList[index].value) {
            this.cityOptions = this.provinceList[index].children
            this.valueCity = ''
            this.originOptions = this.provinceList[index].children[0].children
            this.valueCity = ''
            this.valueOrigin = ''
            // 如果选中省之后想市区默认选中
            // this.valueCity = this.provinceList[index].children[0].value
            // this.valueOrigin = this.provinceList[index].children[0].children[0].value
          }
        })
      },
      // 选择市
      changeCity(val) {
        this.cityList.forEach((city, index) => {
          if (val.toString() === this.cityList[index].value) {
            this.originOptions = this.cityList[index].children
            this.valueOrigin = ''
            //如果选中市之后默认区选中
            // this.valueOrigin = this.cityList[index].children[0].value
          }
        })
      },
      // 选择区
      changeOrigin(val) {
        this.valueOrigin = val
      },
      // 初始化省市区数据
      _getJsonData() {
          console.log('res =======>'+jsonData)
          this.provinceList = []
          this.cityList = []
          this.originList = []
          jsonData.forEach((item) => {
            if (item.value.match(/0000$/)) {
              this.provinceList.push({
                value: item.value,
                label: item.name,
                children: []
              })
            } else if (item.value.match(/00$/)) {
              this.cityList.push({
                value: item.value,
                label: item.name,
                children: []
              })
            } else {
              this.originList.push({
                value: item.value,
                label: item.name
              })
            }
          })
          for (let index in this.provinceList) {
            for (let index1 in this.cityList) {
              if (this.provinceList[index].value.slice(0, 2) === this.cityList[index1].value.slice(0, 2)) {
                this.provinceList[index].children.push(this.cityList[index1])
              }
            }
          }
          for(let item1 in this.cityList) {
            for(let item2 in this.originList) {
              if (this.originList[item2].value.slice(0, 4) === this.cityList[item1].value.slice(0, 4)) {
                this.cityList[item1].children.push(this.originList[item2])
              }
            }
          }
      },


      elecPriceChange : function(){

        if(this.form.elecPriceType=="fixedElecPrice"){

          $("#elePriceDiv").attr("style","display: flex;top: 60vh;height:6vh");
          $("#box2DIv").attr("style","top: 67.5vh;");
          $("#buttonDiv").attr("style","margin-top: 0.9vh;width: 17%;text-align: right;margin-right: 1vh;");

        }else if(this.form.elecPriceType=="variableElecPrice"){
          $("#elePriceDiv").attr("style","display: block;top: 60vh;height:30vh");
          $("#box2DIv").attr("style","top: 91.4vh;");
          $("#buttonDiv").attr("style","margin-top: 18vh;float: right;width: 99%;position: absolute;text-align: right;margin-right: 1vh;");
        }

      },

      buttonClick : function(type,divId){
        for(var i = 1;i<=6;i++){
          $("#hpDiv"+i).css("background","#1f2c6c3b");
        }
        $("#"+divId).css("background","#409EFF");
        this.activeDate = new Date().getTime();
        //路由跳转
        //this.$router.push('/'+type)
      }, 
       
    }
  }
</script>



<style>

.el-table{
  background-color: rgb(20 34 78);
  color: #FFFFFF;
  border-color: rgb(24 63 124 / 51%);
  *{
    border-color: rgb(24 63 124 / 51%) !important;
  }
  .el-table__header-wrapper{
    tr{
      background-color: rgb(10 24 90 / 81%);
      th{
        color: #ffffff;
        background-color: rgba(0,0,0,0.4);
      }
    }
  }
  .el-table__body-wrapper{
    tr{
      background-color: rgb(8 26 80 / 88%);
      &:hover>td{      
        background-color: rgb(13 30 80);
      }
    }
  }
}
  .el-form--inline .el-form-item__content {
      display: inline-block;
      vertical-align: middle;
      margin-left: 1vh;
  }

  .el-radio {
      color: #eff4ff;
      cursor: pointer;
      margin-right: 30px;
  }

  .el-form-item {
      margin-bottom: 5px;
  }
  .el-form-item__label {
      text-align: right;
      vertical-align: middle;
      float: left;
      font-size: 14px;
      color: #f2f2f2;
      line-height: 40px;
      padding: 0 1px 0 0;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
  }
  .el-input__inner { 
      background-color: #202b6180;
      background-image: none;
      border-radius: 4px;
      border: 1px solid #5c7bc5;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
      color: #a3aec5;
      display: inline-block;
      font-size: inherit;
      height: 40px;
      line-height: 40px;
      outline: 0;
      padding: 0 15px;
      -webkit-transition: border-color .2s cubic-bezier(.645,.045,.355,1);
      transition: border-color .2s cubic-bezier(.645,.045,.355,1);
      width: 100%;
  }

  .el-input-group__append, .el-input-group__prepend {
    background-color: #305997;
    color: #ffffff;
    vertical-align: middle;
    display: table-cell;
    position: relative;
    border: 1px solid #506aa7;
    border-radius: 4px;
    padding: 0 20px;
    width: 1px;
    white-space: nowrap;
  }
</style>


<style scoped> 


  /deep/ .el-dialog__body {
        padding: 0px 0px;
        color: #606266;
        font-size: 14px;
        word-break: break-all;
        background: #29377C;
    }

    /deep/ .el-dialog__title {
      line-height: 15px;
      font-size: 16px;
      color: #FFF;
    }


    /deep/ .el-dialog__header {
      padding: 20px 20px 10px;
      color: #FFF;
      background: #374590;
    }

    /deep/ .el-dialog__footer {
      padding: 10px 20px 20px;
      text-align: right;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
      background: #29377C;
    }

  /* 设定地图的大小 */
  .mapDiv{
    width: 97%;
    height: 50vh;
    margin: 1vh auto;
  }


  .buttonStyle {
    height: 4vh;
    width: 24vh;
    display: inline-block;
    -webkit-border-radius: 60px;
    -moz-border-radius: 60px;
    cursor: pointer;
    border-radius: 10px;
    font-family: Arial;
    border: none;
    color: #ffffff;
    font-size: 1.6vh;
    background: #1f2c6c3b;
    border-bottom: 1px solid rgb(64, 158, 255);
    margin: 1.5vh 10px;
    text-align: center;
    line-height: 4vh;
    vertical-align: middle;
    text-decoration: none;
  }

  .box{ 
    width: 98%;
    height: 6vh;
    position: absolute;
    top: 60vh;
    left: 2vh;
    border-radius: 5px;
    margin: auto;
    background: #202b614f;
    border: 1px solid rgb(62 111 219 / 88%);
  }


  .box1{ 

    width: 98%;
    height: 81%;
    top: 1vh;
    left: 2vh;
    text-align: center;
    position: absolute;
    border-radius: 5px;
    margin: auto;
    background: #202b614f;
    border: 1px solid rgb(62 111 219 / 88%);
  }

  .box2 {
    width: 98%;
    height: 12vh;
    margin-top: 1vh;
    margin: auto;
    top: 67.5vh;
    left: 2vh;
    position: absolute;
    border-radius: 5px;
    background: #202b614f;
    border: 1px solid rgb(62 111 219 / 88%);
}

  .titleCss{
    font-size: 22px;
    font-family: inherit;
    font-weight: 500;
    line-height: 1.2;
    color: #f2f2f2;
  }
</style>
